Copyright (c) 1994, The Yucatan Electronic Assembly Company.
This document covers the basic functions needed to use the speller.
A complete class reference will be available soon and will be mailed
to registered users.
Files:
README.DOC - Read This File. SPELLER.CPP - Demo Program to test the library SPELLER.EXE - Compiled version of speller.cpp
SPELL.DOC - This File. (Also Includes simple demo) MAIN.DIC - The main dictionary file. MAIN.INX - The index file for the dictionary. USER.DIC - Fast Dictionary file SPELL.HPP - Header, Include this in youre source. SPELL.LIB - Speller Library. Borland large memory model.
We will soon have support for other compilers. Send
me e-mail if you need a version for another compiler. XMS.H - used by spell.hpp EMS.H - used by spell.hpp
XMM.H - used by spell.hpp
SPOBJS.H - used by spell.hpp
Note: The dictionary files should be in the same directory as the .exe
The following classes are provided:
spell - this is the base spell class.
XmsSpell - store dictionary in XMS memory
CXmsSpell - store dictionary in XMS memory and use compression
DiskSpell - store dictionary on disk
Note: Most debuggers will not work with programs that use XMS memory.
Use DiskSpell while debugging then switch to a faster class for distribution.
Each of the classes have the same primary function derived from spell. You may use
spell as a pointer to the other three classes. This allows your program to change the
storage method at run time.
The following functions are common to all classes:
int check(char *); - Returns 1 if the spelling is verified, otherwise
it returns 0. This function checks to see
if a word is spelled correctly.
int getLastError(); - Returns 0 if no errors have occured
this function should be called after the constructor
to be sure that no file errors have happened.
void SetLevel(int); - This function sets which suggestion algorithm to use.
COMPLEX_MATCH generates the best list of suggestions
TYPOS_MATCH is faster but the list is not as good
int addToTempDic(char *)- This function adds the word to the dictionary.
The word is added to a temporary dictionary and
can be merged with the main dictionary. This allows
words to be double checked before permanently adding
them. The temp.dic file can be edited with a text
editor.
int saveTempDic() - Saves the words added with addToTempDic() to disk.
int ignore(char *) - This stores the word in a dictionary that is never
saved to disk. This function is useful for making
check() ignore some words.
int suggest(char *word);- Generate list of suggestions.
The class suggestion which is a member of spell is used
to retrieve the list of suggestions. See Example.
suggestion->count holds the number of suggestions found.
suggestion->get(n) returns a pointer to the n'th element
in the suggestion list.
Example:
#include "spell.hpp"
#include "iostream.h"
spell *speller; // Use the base class for our pointer
void main(int argc,char **argv)
{
char *wordToCheck = argv[1];
//
//Use DiskSpell for debugging. Most debuggers will not work well when progrms use XMS memory
//when not debugging use one of the other two constructors for speed
//
//speller = new XmsSpell(); // Loads default dictionary files into memory
//speller = new CXmsSpell(); // Loads and compresses default dictionary file into memory
speller = new DiskSpell(); // Opens dictionary files for reading
if (speller->getLastError()) // Check for errors
{
cout << "error loading dictionary \n\r";
delete speller;
return;
}
speller->SetLevel(COMPLEX_MATCH); // Set Suggestion Level COMPLEX_MATCH (Use complex algorithm)
// use TYPOS_MATCH for faster simple algorithm
if (speller->check(wordToCheck)) cout << wordToCheck << " is a correct spelling";
else //the word is mispelled generate suggestions
{
cout << "Possible correct spellings of " << wordToCheck << " are :\n\r";
// Generate correct spelling suggestion list
speller->suggest(wordToCheck);
// Output list of suggestions
for (int i=0; i < speller->suggestion->count; i ++)
{
// ******
// USE SUGGESTION CLASS TO retrieve LIST OF SUGGESTIONS
// -these are the suggestions generated by the suggest function